import {createRouter, createWebHistory, RouteRecordRaw} from "vue-router"
import {userStore} from "@/store"
import systemControl from "./modules/systemControl"
import commControl from "./modules/commControl"
import toolsControl from "@/router/modules/toolsControl";
import logControl from "@/router/modules/logControl";
import settingControl from "@/router/modules/settingControl";
import retailControl from "@/router/modules/retailControl";
import msgControl from "@/router/modules/msgControl";
// import helpControl from "@/router/modules/helpControl";

const routes: ({ redirect: string; path: string; component: any; children: ({ path: string; component: () => Promise<any>; meta: { icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { icon: string; title: string }; name: string })[]; name: string } | { path: string; component: any; children: ({ path: string; component: () => Promise<any>; meta: { roles: string[]; icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { roles: string[]; icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { roles: string[]; icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { roles: string[]; icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { roles: string[]; icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { roles: string[]; icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { roles: string[]; icon: string; title: string }; name: string })[]; meta: { roles: string[]; icon: string; title: string }; name: string } | { path: string; component: any; children: ({ path: string; component: () => Promise<any>; meta: { roles: string[]; icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { roles: string[]; icon: string; title: string }; name: string })[]; meta: { icon: string; title: string }; name: string } | { path: string; component: any; children: ({ path: string; component: () => Promise<any>; meta: { icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { icon: string; title: string }; name: string })[]; meta: { icon: string; title: string }; name: string } | { path: string; component: any; children: { path: string; component: () => Promise<any>; meta: { icon: string; title: string }; name: string }[]; meta: { icon: string; title: string }; name: string } | { path: string; component: any; children: { path: string; component: () => Promise<any>; meta: { icon: string; title: string }; name: string }[]; meta: { icon: string; title: string }; name: string } | { path: string; component: () => Promise<any>; meta: { title: string }; name: string })[] = [
    commControl,
    toolsControl,
    logControl,
    settingControl,
    systemControl,
    msgControl,
    // helpControl,
    retailControl,
    {
        path: '/login',
        name: 'login',
        component: () => import('@/layout/user/Login.vue'),
        meta: {title: '登录页面'}
    }
];

// 创建routes
const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to, from) => {
    const store = userStore();
    if (!store.token && to.fullPath != '/login') {
        router.push("/login")
    }
})

export default router
